package com.manager.controller;

import com.easyCode.feature.mybaits.CustomPage;
import com.easyCode.feature.result.ResponseResultAdvice;
import com.manager.entity.dto.CampusDto;
import com.manager.entity.dto.CampusManagerDto;
import com.manager.entity.dto.ManagerDto;
import com.manager.entity.dto.UserDto;
import com.manager.entity.vo.CampusVo;
import com.manager.service.ICampusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Positive;
import java.util.List;


@Validated
@RestController
@RequestMapping("/campus")
@RequiredArgsConstructor
@ResponseResultAdvice
@Api(tags = "主校区请求")
public class CampusController {
    private final ICampusService iCampusService;

    @ApiOperation("新增主校区")
    @PostMapping("/save")
    public Integer saveCampus(@Validated CampusVo campusVo) {
        return iCampusService.saveCampus(campusVo);
    }

    @ApiOperation("查询主校区")
    @GetMapping("/{id}")
    public CampusDto getCampus(@Positive(message = "参数不合法")@PathVariable("id") Integer id) {
        return iCampusService.getCampusById(id);
    }

    @ApiOperation("分页批量查询主校区")
    @GetMapping("/list")
    public List<CampusDto> listCampus(CustomPage customPage) {
        return iCampusService.listCampus(customPage);
    }

    @ApiOperation("分页批量查询当前主校区下的管理员")
    @GetMapping("/listMangers/{id}")
    public List<CampusManagerDto> listManagesOfCampus(@Positive(message = "参数不合法")@PathVariable("id") Integer id, CustomPage customPage){
        return iCampusService.listManagesOfCampus(id,customPage);
    }

    @ApiOperation("删除主校区")
    @DeleteMapping("/{id}")
    public void delCampus(@Positive(message = "参数不合法")@PathVariable("id") Integer id) {
        iCampusService.delCampusById(id);
    }
}
